﻿using EmailExtractor;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace RealNumbersValidatorTest
{
    [TestClass]
    public class EmailExtractorTest
    {
        static bool CompareListsOfStrings(List<string> list1, List<string> list2)
        {
            if (list1.Count != list2.Count)
            {
                return false;
            }

            for (int i = 0; i < list1.Count; i++)
            {
                if (list1[i] != list2[i])
                {
                    return false;
                }
            }
            return true;
        }

        [TestMethod]
        [DeploymentItem("EmailExtractor.exe")]
        public void ExtractEmailsTest()
        {
            string text = "pesho@mente.com & sasho@bulgaria.bg";
            List<string> expected = new List<string>(new string[] { "pesho@mente.com", "sasho@bulgaria.bg" });
            List<string> actual = EmailExtractor_Accessor.ExtractEmails(text);
            Assert.IsTrue(CompareListsOfStrings(expected, actual));
        }

        [TestMethod]
        [DeploymentItem("EmailExtractor.exe")]
        public void ExtractNoEmailsTest()
        {
            string text = "Heellloooo";
            List<string> expected = new List<string>(new string[] { });
            List<string> actual = EmailExtractor_Accessor.ExtractEmails(text);
            Assert.IsTrue(CompareListsOfStrings(expected, actual));
        }

        [TestMethod]
        [DeploymentItem("EmailExtractor.exe")]
        public void ExtractOneEmailTest()
        {
            string text = "pesho@mente.com";
            List<string> expected = new List<string>(new string[] { "pesho@mente.com" });
            List<string> actual = EmailExtractor_Accessor.ExtractEmails(text);
            Assert.IsTrue(CompareListsOfStrings(expected, actual));
        }

        [TestMethod]
        [DeploymentItem("EmailExtractor.exe")]
        public void ExtractManyEmailsTest()
        {
            string text = @"pesho@mente.com & sasho@bulgaria.bg and then girl90@abv.bg hitman@mail.bg source.bg news.bg
            yahoo.com champions@abv.google.com";
            List<string> expected = new List<string>(new string[] { 
                "pesho@mente.com",
                "sasho@bulgaria.bg",
                "girl90@abv.bg",
                "hitman@mail.bg",
                "champions@abv.google.com"
            });
            List<string> actual = EmailExtractor_Accessor.ExtractEmails(text);
            Assert.IsTrue(CompareListsOfStrings(expected, actual));
        }
    }
}

